package com.jiantong.work.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * Created by niufei on 2017/3/22.
 *
 */
@Data
public class ButcherReportSurveyRecord implements Serializable{

    private static final ObjectMapper objectMapper = JsonMapper.nonEmptyMapper().getMapper();

    private static final long serialVersionUID = -2178542347750425320L;

    /**
     * 主键id
     */
    private Long id;

    /**
     * 申报id
     */
    private Long reportId;

    /**
     * 受理人id
     */
    private Long surveyUserId;

    /**
     * 受理人名称
     */
    private String surveyUserName;

    /**
     * 受理人电话
     */
    private String surveyUserMobile;

    /**
     * 处理意见
     */
    private String handleOpinion;

    /**
     * 宰前合格数
     */
    private Integer beforeSlaughterQualifiedQuantity;

    /**
     * 宰前不合格数
     */
    private Integer beforeSlaughterUnqualifiedQuantity;

    /**
     * 准宰证编号
     */
    private String slaughterCertNumber;

    /**
     * 宰前检查结果
     */
    private String beforeSlaughterResult;

    /**
     * 宰前检查无害化ID
     */
    private Long beforeSlaughterHarmlessId;

    /**
     * 在前检查无害化编号
     */
    private String beforeSlaughterHarmlessNumber;

    /**
     * 检疫人id
     */
    private Long vetUserId;

    /**
     * 检疫人名称
     */
    private String vetUserName;

    /**
     * 检疫人电话
     */
    private String vetUserMobile;

    /**
     * 旋毛虫镜检数量
     */
    private Integer trichinaExamQuantity;

    /**
     * 同步检疫合格数
     */
    private Integer syncQualifiedQuantity;

    /**
     * 同步检疫不合格数(公斤)
     */
    private Float syncUnqualifiedQuantity;

    /**
     * 同步检疫无害化ID
     */
    private Long syncSlaughterHarmlessId;

    /**
     * 同步检疫无害化编号
     */
    private String syncSlaughterHarmlessNumber;

    /**
     * 屠宰检疫合格证
     */
    private String slaughterQuarantineCertNumber;

    /**
     *
     */
    private Map<String , Map<String , String>> slaughterQuarantineCertPhotoMap;

    /**
     * 屠宰检疫合格证照片
     */
    @JsonIgnore
    private String slaughterQuarantineCertPhoto;

    /**
     * 是否卖往本市 -1 外市 1、本市
     */
    private Integer isToLocal;

    /**
     * 目的地地址
     */
    private String targetAddress;

    /**
     * 头部检疫、       酮体检疫、    内脏检疫
     * headerNum : 0 ;ketoneBody : 0 ;internal : 0
     */
    private Map<String , Float> extra;

    /**
     * 扩展信息 头部检疫、酮体检疫、内脏检疫
     */
    @JsonIgnore
    private String extraJson;

    /**
     * 创建时间
     */
    private Date createdAt;

    /**
     * 更新时间
     */
    private Date updatedAt;

    public void setSlaughterQuarantineCertPhoto(String slaughterQuarantineCertPhoto){
        this.slaughterQuarantineCertPhoto = slaughterQuarantineCertPhoto;

        if(Strings.isNullOrEmpty(slaughterQuarantineCertPhoto)){
            this.slaughterQuarantineCertPhotoMap = Maps.newHashMap();
        }else {
            try {
                this.slaughterQuarantineCertPhotoMap = objectMapper.readValue(slaughterQuarantineCertPhoto, new TypeReference<Map<String , Map<String , String>>>() {});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setSlaughterQuarantineCertPhotoMap(Map<String , Map<String , String>> slaughterQuarantineCertPhotoMap)  {
        this.slaughterQuarantineCertPhotoMap = slaughterQuarantineCertPhotoMap;

        if(slaughterQuarantineCertPhotoMap == null || slaughterQuarantineCertPhotoMap.isEmpty()){
            this.slaughterQuarantineCertPhoto = null;
        }else {
            try {
                this.slaughterQuarantineCertPhoto = objectMapper.writeValueAsString(slaughterQuarantineCertPhotoMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck JsonProcessingException
            }
        }
    }

    public void setExtraJson(String extraJson){
        this.extraJson = extraJson;
        if(Strings.isNullOrEmpty(extraJson)){
            this.extra = Maps.newHashMap();
        }else {
            try {
                this.extra = objectMapper.readValue(extraJson, new TypeReference<Map<String ,Float>>() {});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setExtra(Map<String , Float> extra) {
        this.extra = extra;

        if(extra == null || extra.isEmpty()){
            this.extraJson = null;
        }else {
            try {
                this.extraJson = objectMapper.writeValueAsString(extra);
            } catch (JsonProcessingException e) {
                //ignore this fuck JsonProcessingException
            }
        }
    }
}
